package com.base.cn.platform.os.service.netSchoolConfig.publicAccount;

import com.base.cn.platform.os.common.mybatis.BaseBiz;
import com.base.cn.platform.os.common.utils.DataUtil;
import com.base.cn.platform.os.common.utils.StringUtils;
import com.base.cn.platform.os.dao.netSchoolConfig.publicAccount.PublicAccountDao;
import com.base.cn.platform.os.entity.netSchoolConfig.publicAccount.PublicAccount;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 公众号配置Biz
 *
 * @author zsw
 * @since 2019-04-18
 */
@Service
public class PublicAccountBiz extends BaseBiz<PublicAccount,PublicAccountDao> {

    /**
     * 查询公众号配置列表
     *
     * @param publicAccount
     * @return
     */
    public List<PublicAccount> queryPublicAccount(PublicAccount publicAccount) {
        String whereSql = " 1=1";
        if (StringUtils.isNotEmpty(publicAccount.getConfigType())){
            whereSql += " and configType ='" + publicAccount.getConfigType()+"'";
        }
        return this.find(whereSql, null, null);
    }

    /**
     * 保存公众号配置
     *
     * @param publicAccount
     * @return
     */
    public PublicAccount saveAccountConfig(PublicAccount publicAccount){
        if (DataUtil.idIsNotNull(publicAccount.getId())){
            this.updateById(publicAccount,null);
        }else{
            this.save(publicAccount);
        }
        return publicAccount;
    }

    /**
     * 更新公众号配置
     *
     * @param publicAccount
     * @return
     */
    public PublicAccount updateAccountConfig(PublicAccount publicAccount){
        this.updateById(publicAccount,null);
        return publicAccount;
    }

}
